'''
创建页面视图
在urls.py中指定用于将不同的URL路由到其相应视图的模式
'''
from django.shortcuts import render
from django.http import HttpResponse
import re
from django.utils.timezone import datetime

def home(request):
    return HttpResponse("Hello, Django!")
# Create your views here.
'''
def hello_there(request, name):
    now = datetime.now()
    formatted_now = now.strftime("%A, %d %B, %Y at %X")

    # Filter the name argument to letters only using regular expressions. URL arguments
    # can contain arbitrary text, so we restrict to safe characters only.
    match_object = re.match("[a-zA-Z]+", name)

    if match_object:
        clean_name = match_object.group(0)
    else:
        clean_name = "Friend"

    content = "Hello there, " + clean_name + "! It's " + formatted_now
    return HttpResponse(content)
'''

def hello_there(request, name):
    # 使用模板
    return render(
        request,
        'hello/hello_there.html',
        {
            'name': name,
            'date': datetime.now()
        }
    )